<script>
import { defineComponent } from 'vue'
export default defineComponent({
  name: 'SvgIcon'
})
</script>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  name: {
    type: String,
    require: true
  },
  iconClass: Array | String,
  color: String
})

const iconName = computed(() => `#icon-${props.name}`)
const svgClass = computed(() => {
  let svgClassName = 'svg-icon '
  if (props.iconClass) {
    if (typeof props.iconClass === 'string') {
      svgClassName += props.iconClass
    } else {
      svgClassName += props.iconClass.join(' ')
    }
  }
  return svgClassName
})
</script>

<template>
  <svg :class="svgClass" aria-hidden="true">
    <use :xlink:href="iconName" :fill="color" />
  </svg>
</template>

<style lang="scss" scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  position: relative;
  fill: currentColor;
  vertical-align: -2px;
}
</style>
